package com.google.code.gronono.gps.ui.panels;

import javax.swing.GroupLayout;
import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JSeparator;
import javax.swing.GroupLayout.Alignment;
import javax.swing.LayoutStyle.ComponentPlacement;

import com.google.code.gronono.gps.ui.controller.GPSController;

/**
 * Panneau affichant les boutons de l'application.
 *
 * @author Arnaud BRUNET
 */
public class ButtonsPanel extends JPanel {
	/** serialVersionUID. */
	private static final long serialVersionUID = -4970617039270673898L;

	/** Le bouton quitter. */
	private JButton quitBtn;
	/** Le bouton trier. */
	private JButton sortBtn;
	/** Le bouton aperçu. */
    private JButton previewBtn;
    /** Le bouton options. */
    private JButton optionsBtn;
    /** Le bouton reset configuration. */
    private JButton resetBtn;
    /** Le séparateur entre les boutons et le reste de l'application. */
    private JSeparator separator;

    /** Le contrôleur. */
	private final GPSController controller;

	/**
	 * Construit le panneau.
	 * @param controller Le contrôleur.
	 */
    public ButtonsPanel(final GPSController controller) {
    	this.controller = controller;

        initComponents();
        placeComponents();
    }

    /**
     * Initialise les différents composants.
     */
	private void initComponents() {
        separator = new JSeparator();
        quitBtn = new JButton(this.controller.getQuitAction());
        sortBtn = new JButton(this.controller.getSortAction());
        previewBtn = new JButton(this.controller.getPreviewAction());
        optionsBtn = new JButton(this.controller.getOptionsAction());
        resetBtn = new JButton(this.controller.getResetAction());
    }

	/**
     * Place les composants dans le panneau.
     */
	private void placeComponents() {
		final GroupLayout layout = new GroupLayout(this);
        this.setLayout(layout);

        // Horizontalement
        layout.setHorizontalGroup(
            layout.createParallelGroup()
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup()
                    .addComponent(separator)
                    .addGroup(Alignment.TRAILING, layout.createSequentialGroup()
                    	.addContainerGap()
                        .addComponent(resetBtn)
                        .addPreferredGap(ComponentPlacement.RELATED)
                        .addComponent(optionsBtn)
                        .addPreferredGap(ComponentPlacement.RELATED)
                        .addComponent(previewBtn)
                        .addPreferredGap(ComponentPlacement.RELATED)
                        .addComponent(sortBtn)
                        .addPreferredGap(ComponentPlacement.RELATED)
                        .addComponent(quitBtn)
                        .addContainerGap())))
        );
        // Verticalement
        layout.setVerticalGroup(
            layout.createParallelGroup()
            .addGroup(layout.createSequentialGroup()
                .addComponent(separator)
                .addPreferredGap(ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup()
                    .addGroup(layout.createParallelGroup(Alignment.BASELINE)
                        .addComponent(quitBtn)
                        .addComponent(sortBtn)
                        .addComponent(previewBtn)
                        .addComponent(optionsBtn)
                        .addComponent(resetBtn)))
                .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
	}

}
